package review.data;

import java.util.ArrayList;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ReviewForOffer {

	int startSize;
	
	public void runTests(ArrayList<String> codeInjection,
			int codeInjectionSize) {
		ArrayList<String> webElements = new ArrayList<String>();
		webElements.add("email");
		webElements.add("password");
		reviewCodeInjectionsTest(codeInjection, codeInjectionSize, webElements);
	}
	
	private void reviewCodeInjectionsTest(ArrayList<String> codeInjection,
			int codeInjectionSize, ArrayList<String> webElements)  {
		
		for(startSize = 0; startSize < codeInjectionSize; startSize++){
			WebDriver driver = new FirefoxDriver();
			driver.get("https://www.snapsation.com/login/");
			WebElement email = driver.findElement(By.name(webElements.get(0)));
			email.sendKeys("damciodamcio666@gmail.com");
			WebElement password = driver.findElement(By.name(webElements.get(1)));
			password.sendKeys("admin123admin");
			email.submit();
			driver.get("https://www.snapsation.com/offer/show/51b399400e8ef5fe14483282");
			WebElement reviewLink = driver.findElement(By.xpath("(//div[3]/a/span/span)"));
			reviewLink.click();
			WebElement reviewField = driver.findElement(By.xpath("(//textarea)"));
			reviewField.sendKeys(codeInjection.get(startSize));
			reviewField.submit();
		}
		
	}
	
}
